<?php

namespace App\Models\FeishuCallingCard;

use App\Models\BaseModel;
use App\Service\CallingCards\ShareImageService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use function config;

class FeishuCallingCardPosterBackground extends BaseModel
{
    use HasFactory;

    const STATUS_ON  = 1;
    const STATUS_OFF = 0;

    protected $table = 'feishu_calling_card_poster_background';

    protected $fillable = [
        'imageUrl',
        'status',
        'sort',
    ];

    protected $appends = [
        'statusChecked',
        'backgroundUrl',
        'isInternalUseChecked',
        'form',
    ];

    public function getStatusCheckedAttribute()
    {
        return $this->status ? 'checked' : '';
    }

    public function getBackgroundUrlAttribute()
    {
        return config('filesystems.disks.oss.domain') . '/' . $this->imageUrl;
    }

    public function getIsInternalUseCheckedAttribute()
    {
        return $this->isInternalUse ? 'checked' : '';
    }

    public function getFormAttribute()
    {
        return 'form' . $this->id;
    }

    public function refreshPreview()
    {
        ShareImageService::updateBackgroundReview($this);
    }
}
